<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客管理</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css">
</head>

<body>
<!--导航-->
<nav th:replace="admin/_fragments :: menu(1)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header secondary item">管理后台</h2>
            <a href="#" class="active m-item item m-mobile-hide"><i class="idea icon"></i>博客</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="blogs icon"></i>分类</a>
            <a href="#" class="m-item item m-mobile-hide"><i class="blogs icon"></i>标签</a>
            <div class="right m-item m-mobile-hide menu">
                <div class="ui dropdown item">
                    <div class="text">
                        <img class="ui avatar image" src="../../static/images/avatar.jpg">
                        <b>李桃</b>
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="#" class="item">注销</a>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <a href="#" class="ui menu toggle grey icon button m-top-right m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>

<!--二级导航-->
<div class="ui attached pointing inverted menu">
    <div class="ui container">
        <div class="right menu">
            <a href="#" class="item">发布</a>
            <a href="#" class="active teal item">列表</a>
        </div>
    </div>
</div>

<!--中间内容 m-container样式 左右存在间距-->
<div class="m-container m-padded-tb-big">
    <!--根据屏幕的尺寸达到最好的效果 attached浮加  bottom,top圆角-适应移动端-->
    <div class="ui container ">
        <div class="ui secondary center form">
            <div class="inline fields">
                <!--标题输入框-->
                <div class="field type dropdown" style="margin-left: 5em">
                    <input class="type dropdown" type="text" name="title" placeholder="标题">
                </div>
                <!--分类选择框-->
                <div class="field">
                    <div class="ui labeled action input">
                    </div>
                    <div class="ui type selection dropdown">
                        <input type="hidden" name="typeId">
                        <i class="dropdown icon"></i>
                        <div class="default text">分类</div>
                        <div class="menu">
                            <div th:each="type : ${types}" class="item" th:data-value="${type.id}"
                                 th:text="${type.name}"></div>
                        </div>
                    </div>
                    <button id="clear-btn" class="ui clear button m-margin-left-large">重置</button>
                </div>
                <div class="filed m-margin-left-large">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend">
                        <label for="recommend"><span style="color: #fff"><b>推荐</b></span></label>
                    </div>
                </div>
                <div class="field">
                    <button type="button" id="search-btn" class="ui button m-margin-left-large">
                        <i class="search icon"></i> 搜索
                    </button>
                </div>
                <a href="#" th:href="@{/admin/blogs/input}">
                    <button class="ui primary button m-margin-left-large">
                        <i class="add icon"></i> 新增
                    </button>
                </a>
            </div>
            </form>
            <!--表格-->

            <div id="table-container">
                <table th:fragment="blogList" class="ui selectable  inverted single line table">
                    <thead>
                    <tr>
                        <th></th>
                        <th>标题</th>
                        <th>类型</th>
                        <th>推荐</th>
                        <th>状态</th>
                        <th>更新时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="blog,iterStat : ${page.list}">
                        <td th:text="${iterStat.count}">1</td>
                        <td th:text="${blog.title}">刻意练习清单</td>
                        <td th:text="${blog.type.name}">认知升级</td>
                        <td th:text="${blog.recommend} ? '是':'否'">是</td>
                        <td th:text="${blog.published} ? '发布':'草稿'">草稿</td>
                        <td th:text="blog.updateTime ? ${#dates.format(blog.createTime,'yyyy-MM-dd HH:mm')} :${#dates.format(blog.updateTime,'yyyy-MM-dd')}">
                            2017-10-02 09:45
                        </td>
                        <td>
                            <a href="#" th:href="@{/admin/blogs/{id}/input(id=${blog.id})}" class="ui mini blue button"><i
                                    class="edit icon"></i>编辑</a>
                            <a href="#" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}" class="ui mini red button"><i
                                    class="delete icon"></i>删除</a>
                        </td>
                    </tr>
                    </tbody>
                    <!--分页-->
                    <tfoot>
                    <tr>
                        <th colspan="8">
                            <div class="ui inverted divided stackable grid">
                                <div class="three wide column" align="center">
                                    <a class="ui orange left labeled icon button m-margin"
                                       th:href="@{/admin/blogs(pageNum=${page.prePage})}"
                                       th:unless="${page.isFirstPage}"><i class="left arrow icon"></i>上一页 </a>
                                </div>

                                <div class="ten wide column vertical" align="center">
                                    <p>第 <span th:text="${page.pageNum}">1</span> 页，共 <span
                                            th:text="${page.pages}">1</span> 页，有 <span th:text="${page.total}">1</span>
                                        个帖子</p>
                                </div>

                                <div class="three wide column " align="center">
                                    <a class="ui orange right labeled icon button m-margin"
                                       th:href="@{/admin/blogs(pageNum=${page.hasNextPage}?${page.nextPage}:${page.pages})}"
                                       th:unless="${page.isLastPage}">下一页 <i class="right arrow icon"></i></a>
                                </div>
                            </div>
                        </th>
                    </tr>
                    </tfoot>
                </table>
                <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
                    <i class="close icon"></i>
                    <div class="header">提示：</div>
                    <p th:text="${message}">恭喜，操作成功！</p>
                </div>


            </div>
        </div>
    </div>
</div>
<br>
<br>
<br>

<br>

<br>

<!--底部footer-->
<footer th:replace="admin/_fragments :: footer" class="ui inverted divided vertical segment m-padded-tb-massive">
    <div class=" ui stackable center aligned container">
        <div class="ui inverted divided stackable grid">
            <!--二维码-->
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="../../static/images/wechat.jpg" class="ui rounded" style="width: 130px" alt="">
                    </div>
                </div>
            </div>

            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事 (User Story)</a>
                    <a href="#" class="item">用户故事 (User Story)</a>
                    <a href="#" class="item">用户故事 (User Story)</a>
                </div>
            </div>

            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced">联系我</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">Email: 1490477595@qq.com</a>
                    <a href="#" class="item">QQ: 1490477595</a>
                </div>
            </div>

            <div class=" seven wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced">博猪寄语</h4>
                <p class="m-text-thin m-text-spaced m-opacity-mini">
                    你遇到的每个人都是别人想见又见不到的人，请珍惜每一刻相处的时光，因为我们不知道哪一次再见，会变成再也不见。</p>
            </div>
        </div>
        <!--线条-->
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin m-text-spaced m-opacity-small">Copyright © 2020 - 2021 AndyLee</p>
    </div>
</footer>

<!--/*/<th:block th:replace="admin/_fragments :: script">/*/-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
<!--/*/</th:block>/*/-->
<script>
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });
    $('.ui.dropdown').dropdown({
        on: 'hover'
    });

    //消息提示关闭初始化
    $('.message .close')
        .on('click', function () {
            $(this)
                .closest('.message')
                .transition('fade');
        });


    $('#clear-btn')
        .on('click', function () {
            $('.ui.type.dropdown')
                .dropdown('clear')
            ;
        })
    ;

    function page(obj) {
        loadData();
    }

    $("#search-btn").click(function () {
        $("[name='page']").val(0);
        loadData();
    });

    function loadData() {
        $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search", {
            title: $("[name='title']").val(),
            typeId: $("[name='typeId']").val(),
            recommend: $("[name='recommend']").prop('checked'),
        });
    }
</script>

</body>
</html>
